package leetcode.day_2020_11_9_11_15;

import java.util.Arrays;

public class L_673 {
    public static void main(String[] args) {
        int[] arr = new int[]{1,2,4,3,5,4,7,2};
        System.out.println(findNumberOfLIS(arr));
    }

    public static int findNumberOfLIS(int[] nums) {
        int[] dp = new int[nums.length];
        Arrays.fill(dp, 1);
        for(int i=0; i<dp.length; i++) {
            for(int j=0; j<i; j++) {
                if(nums[i] > nums[j]) {
                    dp[i] = Math.max(dp[i], dp[j]+1);
                }
            }
        }
        int res = 0, index = 0;
        for(int k=0; k<dp.length; k++) {
            if(res < dp[k]) {
                res = dp[k];
                index = k;
            }

        }

        int count = 0;
        for(int z=0; z<index; z++) {
            if(dp[z] == res-1)
                count++;
        }

        if(res == 1){
            return dp.length;
        }
        return count;
    }
}
